function rmt(l) { var img = new Image(); img.src = l; document.getElementById('tmp-img').appendChild(img); } 
function myWindow(location, address, gaCategory, gaAction) { var w = 640; var h = 460; var sTop = window.screen.height/2-(h/2); var sLeft = window.screen.width/2-(w/2); var sharer = window.open(address, "myWindow", "status=1,height="+h+",width="+w+",top="+sTop+",left="+sLeft+",resizable=0"); }

function keyfind(e)
{
var code;
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = String.fromCharCode(code);
if($('#header_searchbar').css('display')!='none'){
character=0;}
if(character =='J' || character =='j'){

     var a=new Array();
     var b=new Array();
     var c=new Array();
     var i=0;
     $('.gag-link').each(function(){
        a[i]=$(this).attr('id');
        b[i]=$(this).offset().top; 
        c[i]=$(this).height();
        
        i++;
         });
         var curloc=$(window).scrollTop();
         var j=0;
         var k=0;
         
    for(;j<a.length;){

    if(b[j]+c[j]-39>curloc && curloc >= b[j]-39){
    var k=j;
    break;
    }
    j++;
    }
    if(k == a.length-1){ $('#go-next').click();  }
    $.scrollTo(b[k+1]-38);

}
if(character =='K' || character =='k'){
     var a=new Array();
     var b=new Array();
     var c=new Array();
     var i=0;
     $('.gag-link').each(function(){
        a[i]=$(this).attr('id');
        b[i]=$(this).offset().top; 
        c[i]=$(this).height();
        i++;
         });
         var curloc=$(window).scrollTop();
         var j=0;
         var k=0;
    for(;j<a.length;){
    if(b[j]+c[j]-39>curloc && curloc >= b[j]-39){
    var k=j;
    break;
    }
    j++;
    }
    $.scrollTo(b[k-1]-38);
}
if(character=='L' || character=='l'){
 var a=new Array();
      var b=new Array();
     var i=0;
     $('.gag-link').each(function(){
        a[i]=$(this).attr('gagId');
        b[i]=$(this).offset().top; 
        i++;
         });
          var curloc=$(window).scrollTop();
         var j=0;
    for(;j<a.length;){
    if(b[j]>curloc){
    break;
    }
    j++;
    }
        $.scrollTo('.gag-link:eq('+(j)+')');
        $('#post_love_'+a[j]).trigger('click');
}
if(character=='H' || character=='h'){
 var a=new Array();
      var b=new Array();
     var i=0;
     $('.gag-link').each(function(){
        a[i]=$(this).attr('gagId');
        b[i]=$(this).offset().top; 
        i++;
         });
          var curloc=$(window).scrollTop();
         var j=0;
    for(;j<a.length;){
    if(b[j]>curloc){
    break;
    }
    j++;
    }
        $.scrollTo('.gag-link:eq('+(j)+')');
        $('#vote-down-btn-'+a[j]).trigger('click');
}
if(character=='R' || character=='r'){
window.location.href = "http://xemvl.com/random";
}
}
 $(window).scroll(function () {
    
     var a=new Array();
     var b=new Array();
     var c=new Array();
     var i=0;
     $('.gag-link').each(function(){
        a[i]=$(this).attr('gagId');
        b[i]=$(this).offset().top; 
        c[i]=$(this).height();
        i++;
         });
         var curloc=$(window).scrollTop();
         var j=0;
         var k=0;
         
    for(;j<a.length;){

    if(b[j]+c[j]>curloc && curloc > b[j]){
    var k=j;
    break;
    }
    j++;
    }            
        var winh = $(window).height();
        var ach  = $('#action-'+a[0]).height()+30;
        
        if((curloc > (b[k]+c[k] - ach)) || curloc < b[0]){
        
        $('.scriptolution-stop').css('position','static');
        $('.scriptolution-stop').css('top','!important');
        
        
            }else{
        if((k==0 && curloc >= b[k]) || k>=1){
        $('#action-'+a[k]).css('position','fixed');
        $('#action-'+a[k]).css('top','55px');
        }
            }                
    });
	
$('.search-button').click(function(){
    $('#header_searchbar').toggle('slow');
    });

$('.unlove').click(function(){
        var id=$(this).attr('entryId');
        if( $(this).hasClass('unloved')){
        $(this).removeClass('unloved');
        ulikedeg($(this).attr('entryId'),0,-1);
        }else{
        $(this).addClass('unloved');
        if($('#post_love_'+id).hasClass('loved')){
        ulikedeg($(this).attr('entryId'),-1,1);	
        $('#post_love_'+id).removeClass('loved');
        }else{
        ulikedeg($(this).attr('entryId'),0,1);	
        }
        }
        });
        $('.vote').click(function(){
        var id=$(this).attr('rel');
        if( $(this).hasClass('loved')){
        $(this).removeClass('loved');
        ulikedeg($(this).attr('rel'),-1,0);
        }else{
        $(this).addClass('loved');
        if($('#vote-down-btn-'+id).hasClass('unloved')){
        $('#vote-down-btn-'+id).removeClass('unloved');
        ulikedeg($(this).attr('rel'),1,-1);
        }else{
        ulikedeg($(this).attr('rel'),1,0);
        }
        }
        });        
        function ulikedeg(p,l,u){
        jQuery.ajax({
        type:'POST',
        url:'http://xemvl.com'+ '/votegag.php',
        data:'l='+l+'&pid=' + p +'&u='+u,
        success:function(e){
        $('#love_count_'+p).html(e);
        }
        });
        }  